# app/api/system.py
## 也属于示例性质。。
from fastapi import APIRouter
from datetime import datetime
from app.core.config import settings
from app.utils.request import RequestHandler

router = APIRouter()

@router.get("/", summary="根路径")
async def root():
    return RequestHandler.success(
        data=_get_system_info(),
        message="欢迎使用FastAPI通用基础项目",
        remarks="这是一个灵活的认证系统示例项目"
    )

@router.get("/health", summary="健康检查")
async def health_check():
    return RequestHandler.success(
        data={
            "status": "healthy",
            "timestamp": datetime.now().isoformat(),
            "services": _get_service_status(),
            "feature_flags": _get_feature_flags()
        },
        message="系统运行正常",
        remarks="所有服务均处于健康状态"
    )

def _get_system_info():
    """获取系统基本信息"""
    return {
        "project_name": "FastAPI通用基础项目",
        "version": "1.0.0",
        "auth_status": "enabled" if settings.enable_auth else "disabled",
        "database_status": "enabled" if settings.enable_database else "disabled",
        "user_system_status": "enabled" if settings.enable_user_system else "disabled",
        "debug_mode": settings.debug,
        "docs_url": "/docs" if settings.debug else None,
        "features": _get_feature_flags()
    }

def _get_service_status():
    """获取服务状态"""
    return {
        "authentication": "online" if settings.enable_auth else "disabled",
        "database": "online" if settings.enable_database else "disabled",
        "user_system": "online" if settings.enable_user_system else "disabled",
        "api": "online"
    }

def _get_feature_flags():
    """获取功能开关状态"""
    return {
        "enable_auth": settings.enable_auth,
        "enable_database": settings.enable_database,
        "enable_user_system": settings.enable_user_system,
        "enable_user_registration": settings.enable_user_registration,
        "enable_auto_init_data": settings.enable_auto_init_data,
        "enable_operation_logging": settings.enable_operation_logging
    }